// 展示隐藏效果
// function shuplod() {
//     var status = $(".shuplod").css('display');
//     if (status == "none") {
//         $(".shuplod").show();
//         var boxId = "#shuplod";
//         toBox(boxId);
//     } else {
//         $(".shuplod").hide();
//     }
// }

function findSigns(CertusFormAjax){
    // 请假管理列表
    var leaInfoColumns = [{
        id: 'createUser',
        title: '审批人',
        type: 'string',
        width: 75,
        columnClass: 'text-center',
    },{
        id: 'signTime',
        title: '补签时间',
        type: 'string',
        width: 150,
        columnClass: 'text-center'
    },  {
        id: 'comments',
        title: '说明',
        type: 'string',
        // width: 150,
        columnClass: 'text-left',
    }, {
        id: 'createTime',
        title: '申请时间',
        type: 'date',
        width: 100,
        format: 'yyyy-MM-dd',
        otype: 'time_stamp_ms',
        columnClass: 'text-center'
    },{
        id: 'zt',
        title: '状态',
        type: 'string',
        width: 75,
        columnClass: 'text-center',
        resolution: function (value, record) {
            var content = '';
            if (record.nodeFlag=="1"){
                content += '申请中';
            }else if (record.nodeFlag=="2"){
                content += '已退回';
            }else if (record.nodeFlag=="3"){
                content += '拒绝';
            }else if (record.nodeFlag=="4"){
                content += '待审批';
            }else if (record.nodeFlag=="5"){
                content += '审批通过';
            }

            return content;
        }
    }];
    CertusFormAjax.ajax('findSignList',{},function (response) {
        var leaInfoOption = {
            lang: 'zh-cn',
            ajaxLoad: false,
            // loadURL:'url',
            exportFileName: '补签列表',
            datas: response.data,
            columns: leaInfoColumns,
            gridContainer: 'signInfoContainer',
            toolbarContainer: 'signToolBarContainer',
            tools: '',
            extraWidth: 20,
            pageSize: 10,
            pageSizeLimit: [10, 15, 20]
        };
        var leaInfoGrid = $.fn.dlshouwen.grid.init(leaInfoOption);
        leaInfoGrid.load();
    });

    //查询审批人信息
    CertusFormAjax.ajax("findSpinfos",{"code":"%QJLC%"},function(response){
        var data  = response.data;
        var oabtColumns = [{
            id: 'userName',
            title: '审批人',
            type: 'string',
            width: 75,
            columnClass: 'text-center',
        }
        // ,{
        //     id: 'departmentCode',
        //     title: '所属部门',
        //     type: 'string',
        //     columnClass: 'text-center',
        // }
        ,{
            id: 'company',
            title: '所属公司',
            type: 'string',
            columnClass: 'text-center',
            resolution: function (value, record) {
                var content = '';
                if (record.company=="HFKJ"){
                    content += '浩方科技';
                }else if (record.company=="HFXX"){
                    content += '浩方信息';
                }else if (record.company=="STSBJ"){
                    content += '赛特斯北京';
                }else if (record.company=="STSGD"){
                    content += '赛特斯广东';
                }else if (record.company=="STSJT"){
                    content += '赛特斯集团';
                }else if (record.company=="STSNJ"){
                    content += '赛特斯南京';
                }else if(record.company=="STSSH"){
                    content += '赛特斯上海';
                }else if(record.company=="SYB-RX"){
                    content += '融合运维事业部';
                }
                return content;
            }
        }, {
            id: 'comments',
            title: '职位',
            type: 'string',
            columnClass: 'text-center',
        }, {
            id: 'approveLevel',
            title: '审批级别',
            type: 'string',
            width: 75,
            columnClass: 'text-center',
        }, {
            id: 'minValue',
            title: '天数',
            type: 'string',
            width: 50,
            columnClass: 'text-center',
        }];
        var oabtOption = {
            lang: 'zh-cn',
            ajaxLoad: false,
            // loadURL:'url',
            exportFileName: '出差计划列表',
            datas:data,
            columns: oabtColumns,
            gridContainer: 'spContainer',
            toolbarContainer: 'spToolContainer',
            tools: '',
            pageSize: 10,
            pageSizeLimit: [10, 15, 20]
        };
        oabtGrid= $.fn.dlshouwen.grid.init(oabtOption);
        oabtGrid.load();
    });
}

function addSign($scope, CertusFormAjax) {
    CertusFormAjax.ajax('initDepts',{},function (response) {
        var data = response.data;
        $scope.depts = data;
        if (data.length==1){
            $("#deptCode").attr("disabled","disabled");
        }
        $scope.deptCode = data[0].departmentCode;
    });

    CertusFormAjax.ajax('findScdules',{"userId":""},function (response) {
        var data = response.data;
        $scope.typeId = data.typeId;
        $scope.workTime = data.workTime;
        $scope.onTimeMorning = data.onTimeMorning;
        $scope.offTimeMorning = data.offTimeMorning;
        $scope.deadlineMorning = data.deadlineMorning;
        $scope.onTimeAfternoon = data.onTimeAfternoon;
        $scope.offTimeAfternoon = data.offTimeAfternoon;
        $scope.comments = data.comments;
    });

    CertusFormAjax.ajax('findLastBqxx',{},function (response) {
        $scope.bqxx = response.data;
    });

    $(".submit").on('click',function () {

        var beginTime = $("#beginTime").val();
        var hour1 = "";
        var min1 = "";
        if (beginTime!=""){
            var data = new Date();
            var startTime = new Date(beginTime.replace("/", "-").replace("/", "-"));
            if (startTime>data){
                layer.msg("补卡日期不能大于当前日期");
                return;
            }
        }

        CertusFormAjax.ajax('getBqNums',{"beginTime":beginTime},function (result) {
            if (result.data>=2){
                layer.msg("本月补签次数已经达到2次");
                return;
            }else{
                var deptCode = $("#deptCode").val();

                hour1 = $("#hour").val();
                min1 = $("#min").val();
                beginTime += " "+hour1+":"+min1;
                // var beginTime2 = $("#beginTime2").val();
                // var hour2 = "";
                // var min2 = "";
                // if (beginTime2!=""){
                //     var startTime2 = new Date(beginTime2.replace("/", "-").replace("/", "-"));
                //     if (startTime2>data){
                //         layer.msg("补卡日期不能大于当前日期");
                //         return;
                //     }
                //
                //     hour2 = $("#hour2").val();
                //     min2 = $("#min2").val();
                //     beginTime2 += " "+hour2+":"+min2;
                // }
                // if (beginTime==""&&beginTime2==""){
                //     layer.msg("至少填写一个打卡时间");
                //     return;
                // }

                if (beginTime==""&&beginTime2==""){
                    layer.msg("补卡日期不能为空");
                    return;
                }
                var comments = $("#comments").val();

                CertusFormAjax.ajax('addSign',{"deptCode":deptCode,"beginTime":beginTime,"beginTime2":"",
                    "comments":comments},function () {
                    layer.msg("提交成功");
                    window.history.back();
                });
            }
        });
    });
}